import React from 'react';
import { connect } from 'react-redux';
import { Route, Redirect } from 'react-router-dom';
function ProtectedRoute ({ user,component : Component, ...rest }) {
	return (
		<Route
			{...rest}
			render={props =>
				user.token ? (
					<Component {...props} />
				) : (
					<Redirect
						to={{
							pathname : '/login',
							state : { from : props.location.pathname }
						}}
					/>
				)
			}
		/>
	);
}


export default connect(state => state)(ProtectedRoute);
